import axios from 'axios'

import { createApp } from 'vue'
import { createPinia } from 'pinia'

import App from './App.vue'
import router from './router'
import {prompt} from './publicMethods'


const app = createApp(App)

app.use(createPinia())
app.use(router)


function axiosToken(data){
    if(!data.headers)data.headers = {};
    data.url = import.meta.env.VITE_API_URL+data.url;
    data.headers.Authorization = localStorage.getItem('token');
    return axios(data);
}

function dateFormat(time){
    let dateData = new Date(time*1000); 
    let year = dateData.getFullYear();
    let month = dateData.getMonth() + 1;
    let date = dateData.getDate();
    return year+'年'+month+'月'+date+'日';
}


app.provide('global',{
    axios,
    axiosToken,
    dateFormat,
    prompt
})


app.mount('#app')
